package nju.bishe.weibo;



import java.util.ArrayList;

import nju.bishe.weibo.ui.base.WithHeaderActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class SuggestionActivity extends WithHeaderActivity{

	private ArrayAdapter mAdapter;
	
	private String userId;
	private static final String LAUNCH_ACTION = "nju.bishe.weibo.SUGGESTION";

	private static final String TAG = "SuggestionActivity";

	String myself="";
	private String category="default";
	public static String CATEGORY;
	private ArrayList<String> categories=new ArrayList<String>();
	private String[] categoriesContents;
	@Override
	protected boolean _onCreate(Bundle savedInstanceState) {
		Log.i(TAG, "onCreate()...");
		if (super._onCreate(savedInstanceState)) {
			System.out.println("");
			setContentView(R.layout.categories);
			categoriesContents=getResources().getStringArray(R.array.categories);
			mAdapter=new ArrayAdapter<CharSequence>(this, R.layout.category_item, categoriesContents);
			setCategories();
			//ListView lv=new ListView(this);
			ListView lv=(ListView)findViewById(R.id.categories_list);
		      lv.setAdapter(mAdapter);
		      lv.setTextFilterEnabled(true);
		      
		      lv.setOnItemClickListener(new OnItemClickListener(){
		  @Override
		  public void onItemClick(AdapterView<?> av, View v, int i,long l) {
			  // TODO Auto-generated method stub
			  category=categories.get(i);
			  Log.i(TAG, category);
			  getSuggestion(category);
		  }});
		    
		    initHeader(HEADER_STYLE_HOME);
		       
		    
			setHeaderTitle("请选择一个推荐分类");

			return true;
		} else {
			return false;
		}
	}
	
	
	private void setCategories(){
		categories.add("default");
		categories.add("ent");
		categories.add("hk_famous");
		categories.add("cooking");
		categories.add("model");
		categories.add("sport");
		categories.add("finance");
		categories.add("tech");
		categories.add("singer");
		categories.add("writer");
		categories.add("moderator");
		categories.add("medium");
		categories.add("stockplayer");
	}
	
	/*
	 * 
	 */
	
	protected void getSuggestion(String category){
		Intent intent = new Intent();
		intent.putExtra(SuggestionActivity.CATEGORY, category);
		intent.setClass(SuggestionActivity.this, SuggestionResultActivity.class);

		startActivity(intent);
		
	}
}
